-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: Following generation mode when generating test targets #2044
Conversation
In order for this to be mergeable we should be the policy outlined here: https://rules-python.readthedocs.io/en/latest/contributing.html#breaking-changes So we should go with the approach of an extra directive, which we may later set to default to some other value than today. Maybe it could default to |
Added the directive and updated readme to include the macro. Please take another look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, added a CHANGELOG entry for a future release announcement.
When
python_generation_mode
isproject
orfile
, the generatedpy_test
targets are consistent withpy_library
. However, whenpython_generation_mode
ispackage
, it becomes inconsistent: it requires either__test__
target or__test__.py
file to generatepy_test
in package mode, otherwise it will fall back to file mode.This PR relaxes this requirement with a new directive
gazelle:python_generation_mode_per_package_require_test_entry_point
. Whent it's set to false, Gazelle and generates onepy_test
target per package in package mode even without entry points.This allows people to use
gazelle:map_kind
to mappy_test
to a macro that sets a default test runner, such as rules_python_pytest or pytest-bazel, and generate one test target per package. The behavior whengazelle:python_generation_mode
is "file" or "project" remains the same.This fixes #1972 for supporting pytest from Gazelle. With this approach, people can define a thin macro like this to use py_pytest_main:
BREAKING CHANGES:
Without
gazelle:map_kind
or__test__
target or__test__.py
, the package mode will now generatepy_test
withoutmain
attribute, which may not be runnable. However, this is already an issue with "python_generation_mode:project" before this PR.The default value of
gazelle:python_generation_mode_per_package_require_test_entry_point
is true to preserve the current behavior. We will flip that default value in the future.